博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mootools_使用MooTools进行评论预览
阅读量:2514 次
发布时间:2019-05-11

本文共 2903 字,大约阅读时间需要 9 分钟。

mootools

Comment previewing is an awesome addition to any blog. I've seen really simple comment previewing and some really complex comment previewing. The following is a tutorial on creating very basic comment previewing using MooTools.

评论预览是对任何博客的补充。 我看过非常简单的评论预览和一些非常复杂的评论预览。 以下是有关使用MooTools创建非常基本的注释预览的教程。

XHTML (The XHTML)

Your Name:

Your Email:
Your Website:
Your Comment:

You can set up your XHTML any way you'd like. It's important for the sake of consistency to make your preview display look as closely as possible to your real comments display.

您可以根据需要设置XHTML。 为了保持一致性,重要的是使预览显示与实际评论显示尽可能接近。

CSS (The CSS)

.lp-block		{ width:400px; float:left; }.lp-block input, .lp-block textarea { width:90%; }#live-preview-display 	{ background:#eee; padding:10px; margin-left:50px; margin-top:20px; }#lp-name { font-weight:bold; }#lp-avatar { float:right; margin:0 0 20px 20px; }#lp-comment { padding-top:10px; font-style:italic; line-height:19px; }

Make your "preview" CSS look just like your real comments display.

使您的“预览” CSS看起来就像您的实际注释显示一样。

MooTools JavaScript (The MooTools JavaScript)

(function($){	window.addEvent('domready',function(){		//the build process		var build = function() {			//vars (fields) and blocks			var lpcomment = $('lp-comment'), lpname = $('lp-name'), lpavatar = $('lp-avatar');			var name = $('name'), email = $('email'), website = $('website'), comment = $('comment');						//comment			lpcomment.set('text',comment.value);			lpcomment.set('html',lpcomment.get('html').replace(/\n/g,'
')); //name & websites if(website.value && (website.value).test(/http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{2}/)) { lpname.set('html','' + name.value + ' says:'); } else { lpname.set('text',name.value + ' says:'); } //gravatar if(email.value && (email.value).test(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/)) { var md5Email = MD5(email.value); lpavatar.set('html',''); } }; //comment...easy $$('#live-preview-form input, #live-preview-form textarea').addEvents({ keyup: build, blur: build }); });})(document.id);

The JavaScript is quite easy. Note that I'm doing very basic validation and formatting -- you may get as fancy or simple as you'd like. Also note that I'm using an MD5 function for the gravatar functionality. The MD5 function was .

JavaScript非常简单。 请注意,我正在做非常基本的验证和格式化-您可能会喜欢上自己想像的或简单的。 另请注意,我使用的是MD5功能的Gravatar功能。 在 MD5功能。

This is as basic as it gets. You may want to implement functionality that checks for valid URLs and email addresses. You may also want to implement a regular expression that turns two line breaks into </p><p> tags. If you'd like to implement a more sophisticated system, I highly recommend using Thomas Aylott's .

这是最基本的。 您可能想要实现检查有效URL和电子邮件地址的功能。 您可能还想实现一个将两个换行符转换为</ p> <p>标记的正则表达式。 如果您想实现一个更复杂的系统,我强烈建议您使用Thomas Aylott的 。

翻译自:

mootools

转载地址:http://supwd.baihongyu.com/

你可能感兴趣的文章
atitit 读书与获取知识资料的attilax的总结.docx
查看>>
B站 React教程笔记day2(3)React-Redux
查看>>
找了一个api管理工具
查看>>
Part 2 - Fundamentals(4-10)
查看>>
使用Postmark测试后端存储性能
查看>>
NSTextView 文字链接的定制化
查看>>
第五天站立会议内容
查看>>
ATMEGA16 IOport相关汇总
查看>>
JAVA基础-多线程
查看>>
面试题5:字符串替换空格
查看>>
[Codevs] 线段树练习5
查看>>
Amazon
查看>>
component-based scene model
查看>>
Echart输出图形
查看>>
hMailServer搭建简单邮件系统
查看>>
从零开始学习jQuery
查看>>
Spring+SpringMVC+MyBatis深入学习及搭建(四)——MyBatis输入映射与输出映射
查看>>
opacity半透明兼容ie8。。。。ie8半透明
查看>>
CDOJ_24 八球胜负
查看>>
Alpha 冲刺 (7/10)
查看>>